#include <iostream>
#include <cstring>
using namespace std;
int isPrime(int num) {
  if (num <= 1) {
    return 0; // 0 - false, 1 - true
  }
  for (int i = 2; i * i <= num; ++i) {
    if (num % i == 0) {
      return 0;
    }
  }
  return 1;
}
int findClosestPrime(int num) {
  if (isPrime(num)) {
    return num;
  }
  int lowerPrime = num - 1;
  int upperPrime = num + 1;
  while (1) {
    if (isPrime(lowerPrime)) {
      return lowerPrime;
    }
    if (isPrime(upperPrime)) {
      return upperPrime;
    }
    --lowerPrime;
    ++upperPrime;
  }
}
int main() {
  char word1[10], word2[10], word3[10];
  cin >> word1 >> word2 >> word3;
  const char *words[] = {"zero", "one", "two", "three", "four",
                         "five", "six", "seven", "eight", "nine"};
  int digit1 = -1, digit2 = -1, digit3 = -1;
  for (int i = 0; i < 10; ++i) {
    if (strcmp(word1, words[i]) == 0) digit1 = i;
    if (strcmp(word2, words[i]) == 0) digit2 = i;
    if (strcmp(word3, words[i]) == 0) digit3 = i;
  }
  if (digit1 == -1 || digit2 == -1 || digit3 == -1) {
    cout << "Wrong input" << endl;
    return 0;
  }
  int number = digit1 * 100 + digit2 * 10 + digit3;
  cout << findClosestPrime(number) << endl;
  return 0;
}
